package com.neuedu.spring.controller;

import com.neuedu.spring.dao.IUserDao;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.BeanFactoryAware;
import org.springframework.beans.factory.BeanNameAware;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Controller;

/**
 * 项目：      spring-framework
 * 类名:       RoleController
 * 创建时间：  2024/3/12 15：32
 * 描述 :
 * 作者 :     张金山
 * QQ :     314649444
 * Site:      https://jshand.gitee.io
 */
@Controller
public class RoleController implements BeanPostProcessor , BeanNameAware , BeanFactoryAware, ApplicationContextAware {


    private IUserDao userDao;


    public RoleController(@Autowired IUserDao userDao) {
        this.userDao = userDao;
        System.out.println("RoleController.RoleController 被调用了");
    }

    /**
     * 能够获取到容器中的 bean 实例 以及名字
     * @param bean the new bean instance
     * @param beanName the name of the bean
     * @return
     * @throws BeansException
     */
    @Override
    public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
        //可以做处理。。。。。。
        System.out.println(" beanName "+beanName);
        System.out.println(" bean "+bean);
        return bean;
    }

    @Override
    public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
        System.out.println("RoleController.postProcessAfterInitialization 被调用了 beanName  = "+beanName);
        return bean;
    }

    @Override
    public void setBeanName(String name) {
        System.out.println("当前的Bean的名字  name = " + name);
    }

    /**
     * 获取IOC容器对象
     * @param beanFactory owning BeanFactory (never {@code null}).
     * The bean can immediately call methods on the factory.
     * @throws BeansException
     */
    @Override
    public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
        System.out.println("beanFactory = " + beanFactory);
    }


    /*
     * 获取到ioc容器
     */
    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        System.out.println("applicationContext = " + applicationContext);
        applicationContext.getParentBeanFactory();

    }





}
